﻿Imports System.Drawing.Color
Imports System.ComponentModel

Public Class FocusedTextBox

    Dim _mandatory As Boolean
    Dim _enterFocusColor, _leaveFocusColor As Color
    Dim _mandatoryColor As Color
    Dim firstEntry As Boolean = True

    <Description("Indicates whether the contIf _mandatory And Me.Text.Length = 0 Then

        Else
            Me.BackColor = Me._enterFocusColor
        End Ifrol can be left blank"), Category("Mycategory"), DefaultValue(False)> _
    Public Property Mandatory() As Boolean
        Get
            Return _mandatory
        End Get
        Set(ByVal value As Boolean)
            _mandatory = value
        End Set
    End Property

    <Description("Indicates the controls color when it gets focus"), Category("Mycategory")> _
    Public Property EnterFocusColor() As System.Drawing.Color
        Get
            Return _enterFocusColor
        End Get
        Set(ByVal value As System.Drawing.Color)
            _enterFocusColor = value
        End Set
    End Property

    <Description("Indicates the controls color when it's mandatory and left balnk"), Category("Mycategory")> _
    Public Property MandatoryColor() As Color
        Get
            Return _mandatoryColor
        End Get
        Set(ByVal value As Color)
            _mandatoryColor = value
        End Set
    End Property

    Private Sub FocusedTextBox_Enter(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Enter
        If firstEntry Then
            Me._leaveFocusColor = Me.BackColor
            firstEntry = False
        End If
        Me.BackColor = Me._enterFocusColor
    End Sub

    Private Sub FocusedTextBox_Leave(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Leave
        If _mandatory And Me.Text.Length = 0 Then
            Me.BackColor = Me._leaveFocusColor



        Else
            Me.BackColor = Me._leaveFocusColor
            Me.BackColor = Me._mandatoryColor
        End If

        If _mandatory And Me.Text.Length = 0 Then
            Me.BackColor = Me._leaveFocusColor



        Else
            Me.BackColor = Me._enterFocusColor
        End If
        If _mandatory And Me.Text.Length = 0 Then

        Else
            Me.BackColor = Me._enterFocusColor
        End If
    End Sub
End Class
